package com.xzit.tmms.controller.course;


import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


import org.springframework.ui.Model;

import com.xzit.tmms.bean.unit.Course;
import com.xzit.tmms.common.base.BaseController;
import com.xzit.tmms.common.exception.ServiceException;
import com.xzit.tmms.common.page.Page;
import com.xzit.tmms.service.course.CourseService;

@Controller
@RequestMapping("/course")
public class CourseController extends BaseController{
	@Resource
	private CourseService courseService;
	
	@RequestMapping("")
	public String index(){
		return "course/course-index";
	}
	
	/**
	 * @Title: queryCourse
	 * @Description: TODO 查询课程
	 */
	@RequestMapping("queryCourse")
	public String queryCourse(Model model) throws ServiceException{
		Page<Map<String,Object>> page = new Page<>(getPageIndex(), getPageSize());
		model.addAttribute("page",courseService.queryCourse(page));
		return "course/course-query";
	}
	
	@RequestMapping("/addCourse")
	public String addCourse(Model model) throws ServiceException{
		model.addAttribute("modelList",courseService.getModelList());
		return "course/course-add";
		
	}
	
	@RequestMapping("/addCourseSubmit")
	public String addCourseSubmit(Course course) throws ServiceException{
		courseService.addCourse(course);
		return "redirect:/course.action";
	}
	
	@RequestMapping("/deleteCourse")
	public String deleteCourse(Integer courseId) throws ServiceException{
		courseService.deleteCourse(courseId);
		return "forward:queryCourse.action";
		
	}
	
	@RequestMapping("/updateCourse")
	public String updateCourse(Model model,Integer courseId) throws ServiceException{
		Course course = courseService.getCourseById(courseId);
		System.out.println("ffffffffffffffffffffffffffffffff"+courseId);
		model.addAttribute("course",course);
		model.addAttribute("modelList",courseService.getModelList());
		return "course/course-update";
		
	}
	
	@RequestMapping("/updateCouseSubmit")
	public String updateCouseSubmit(Model model,Course course) throws ServiceException{
		courseService.updateCourse(course);
		return "redirect:/ course.action";
	}
}
